//
//  SEApiManager.swift
//  SmartEyeForPatient
//
//  Created by qdsg on 2021/4/14.
//

import UIKit

// MARK - ECApiEnvironment

enum ECApiEnvironment {
    /// 本地
    case local
    /// 测试
    case test
    /// 生产
    case produce

    var baseUrl: String {
        switch self {
        case .local:
//            return "https://nf-api-local.qdsgvision.com:55555"
            return "http://192.168.1.62:55555"
        case .test:
            return "https://nf-api-test.qdsgvision.com:20443"
        case .produce:
            return "https://nf-api.qdsgvision.com"
        }
    }
    
    var websocketUrl: String {
        switch self {
        case .local:
            return "ws://192.168.1.149:8888/newfuture?userId=\(UserDefaults.userId)&token=\(UserDefaults.authToken)&platType=0"
        case .test:
            return "ws://183.249.1.200:48888/newfuture?userId=\(UserDefaults.userId)&token=\(UserDefaults.authToken)&platType=0"
        case .produce:
            return "wss://nf-websocket.qdsgvision.com/newfuture?userId=\(UserDefaults.userId)&token=\(UserDefaults.authToken)&platType=0"
        }
    }

    var aireportBaseUrl: String {
        switch self {
        case .local:
            return "http://192.168.1.75:3400/#/check-report?token=\(UserDefaults.authToken)"
        case .test:
            return "https://smarteye-h5-test.qdsgvision.com/#/check-report?token=\(UserDefaults.authToken)"
        case .produce:
            return "https://smarteye-h5.qdsgvision.com/#/check-report?token=\(UserDefaults.authToken)"
        }
    }

    var appStoreUrl: String {
        return "https://itunes.apple.com"
    }
}

// MARK: - SEApiManager

struct SEApiManager {

    #if DEVELOPER
        private static let environment: ECApiEnvironment = .test
    #else
        private static let environment: ECApiEnvironment = .produce
    #endif

    static var baseUrl: String { environment.baseUrl }

    static var websocketUrl: String { environment.websocketUrl }

    static func examineAIReportUrl(applyFormId: String, hospitalId: String, status: Int) -> String {
        return "\(SEApiManager.environment.aireportBaseUrl)&id=\(applyFormId)&orgId=\(hospitalId)&status=\(status)"
    }

    static var appStoreUrl: String { environment.appStoreUrl }

    static var headers: [String: String] {
        return ["Authorization": UserDefaults.authToken,
                "Source": source]
    }
    
    private static var source: String {
        let dic = ["source": UIDevice.source,
                   "brand": UIDevice.brand,
                   "model": UIDevice.model,
                   "osVersion": UIDevice.osVersion,
                   "appVersion": UIDevice.appVersion]
        return dic.toJsonString() ?? ""
    }
    

}
